home *** CD-ROM | disk | FTP | other *** search
- /*
- * AmiTCP_session version 1.0
- *
- * Arexx script to dial a SLIP server, start AmiTCP, send mail, etc.
- * Usage: AmiTCP_session.rexx
- *
- * Written by David Jameson, 1994
- * based on AmiTCP_dialup by K. Raquel Sanborn
- */
-
- /* Constants */
-
- cr = '0d'x
- hangup_str = 'ATH'||cr
- phone_number = 'PHONE' /* Put telephone number here */
- username = 'USERNAME'||cr /* Put your user name here */
- passwd = 'PASSWORD'||cr /* Put your password here */
- logfile = 'ncomm:ncomm.log' /* Put name of log-file here */
- nntpserver = 'news.gpl.net' /* Put name of NNTP server here */
- serial_speed = 57600 /* Put speed of serial port here */
- slip_device = 'rhcslip.device' /* Name of slip device */
- active_file = 'uulib:active' /* Name of active file */
- dialstr = 'ATDT'||phone_number||cr
-
-
- /* Open libraries */
-
- if ~show('L', 'rexxsupport.library') then do
- if addlib('rexxsupport.library', 0, -30, 0) then
- say 'added rexxsupport.library'
- else do
- say 'failed to open rexxsupport.library'
- exit 10
- end
- end
-
- if ~show('L', 'rexxserdev.library') then do
- if addlib('rexxserdev.library', 0, -30, 5) then
- say 'added rexxserdev.library'
- else do
- say 'failed to open rexxserdev.library'
- exit 10
- end
- end
-
- say 'Starting AmiTCP...'
- address command
- 'amitcp:bin/startnet'
-
- say 'Starting smtpd...'
- 'run smtpd'
-
- serhandle = SerOpen('serial.device', 0)
- if serhandle = 0 then do
- say 'Failed to open serial device'
- exit 1
- end
-
- check = SerClear(serhandle)
- check = SerSetParms(serhandle, serial_speed, 8, N, 1, 0 )
-
- buffer = allocmem(4096)
- junk = c2d(buffer)
-
- /* Clean up when ctrl-C pressed */
- signal on break_c
-
- say 'Dialing the terminal server... '
- check = 0
- do forever
- if (check == 0) then
- do
- result = SerWrite(serhandle, dialstr, length(dialstr))
- check = 1
- totalstr = ''
- end
- status = SerQuery(serhandle)
- parse upper var status valid bytes_read status_bits .
- rcvdstr = SerRead(serhandle, junk, bytes_read)
- totalstr = totalstr||rcvdstr
- check = modem_query(totalstr)
- if (check == 100) then leave
- result = delay(100)
- end
-
- totalstr = ''
-
- check = SerFlush(serhandle, 'R')
- say 'Modem has connected to the terminal server...'
-
- check = 0
- do until check = 1
- say 'Sending CR to server...'
- check = SerWrite(serhandle, cr, length(cr))
- check = wait_str(':')
- end
-
- say 'Received user prompt...'
- check = SerWrite(serhandle, username, length(username))
- check = SerRead(serhandle, junk, length(username))
- say 'Sent Username, now waiting for password prompt...'
-
- check = 0
- do until check = 1
- check = wait_str(':')
- end
- say 'Received password prompt...'
- check = SerWrite(serhandle, passwd, length(passwd))
- say 'Sent password...'
-
- check = SerClose(serhandle)
- serhandle = 0 /* Just in case ctrl-C is pressed */
- check = freemem(buffer,4096)
- buffer = 0
-
- say 'Putting SLIP online'
- 'online' slip_device '0'
-
- /* First try to open existing log file */
- check = open('log', logfile, 'a')
-
- /* That didn't work, so now create a new log file */
- if (check == 0) then do
- check = open('log', logfile, 'w')
- if (check == 0) then do
- say "Failed to open log file"
- exit
- end
- end
-
- say 'Logging start of call...'
- check = writeln('log', 'AMITCP');
- check = writeln('log', '--------------------------------');
- weekday = left(date(weekday), 3)
- date = date()
- parse var date day month year
- time1 = time()
- parse var time1 hour1 ':' min1 ':' sec1
- check = writeln('log', 'Login: ' weekday month day||' '||time1||year);
-
- say 'Sending outgoing mail (if any)...'
- 'breakname smtpd f'
-
- say 'Sending outgoing news (if any)...'
- 'list uunews:NNTPSpoolDir lformat "nntppost <%p%n*ndelete %p%n" to t:post'
- 'execute t:post'
- 'delete >nil: t:post'
-
- say 'Beginning nntp transfer...'
- 'run nntpxfer' nntpserver active_file
-
- /* Wait until user clicks on the 'OK' button */
- 'RequestChoice "AmiTCP Front-end" "Click to close AmiTCP session" QUIT >nil:'
-
- say 'Killing AmiTCP...'
- 'offline' slip_device '0' /* Just in case AmiTCP doesn't get killed */
-
- address AMITCP
- 'KILL'
- check = delay(150)
-
- say 'Closing connection...'
-
- serhandle = SerOpen('serial.device', 0)
- check = SerClear(serhandle)
- check = SerSetParms(serhandle, serial_speed, 8, N, 1, 0)
-
- /* Send +++, wait the send ATH, then exit */
-
- say 'Sending +++'
- check = delay(75)
- check = SerWrite(serhandle, '+++', length('+++'))
- check = delay(75)
- say 'Sending ATH<cr>'
- check = SerWrite(serhandle, 'A', 1)
- check = delay(2)
- check = SerWrite(serhandle, 'T', 1)
- check = delay(2)
- check = SerWrite(serhandle, 'H', 1)
- check = delay(2)
- check = SerWrite(serhandle, cr, 1)
- check = delay(25)
- check = SerClose(serhandle)
- serhandle = 0
-
- say 'Logging end of call...'
-
- time2 = time()
- date = date()
- weekday = left(date(week), 3)
- parse var date day month year
- check = writeln('log', 'Logout:' weekday month day||' '||time2||year);
- parse var time2 hour2 ':' min2 ':' sec2
-
- /* Calculate time online */
- diffsecs = sec2 - sec1
- diffmins = min2 - min1
- diffhours = hour2 - hour1
- if diffsecs < 0 then do
- diffsecs = diffsecs + 60
- diffmins = diffmins - 1
- end
- if diffmins < 0 then do
- diffmins = diffmins + 60
- diffhours = diffhours - 1
- end
- if diffhours < 0 then do
- diffhours = diffhours + 24
- end
-
- /* Pad out digits with leading 0s */
- diffsecs = right(diffsecs, 2, '0')
- diffmins = right(diffmins, 2, '0')
- diffhours = right(diffhours, 2, '0')
-
- check = writeln('log', 'Time online: 'diffhours||':'||diffmins||':'||diffsecs);
- check = writeln('log', '')
- check = close('log')
-
- say 'Done!'
-
- exit 0
-
-
- /*
- * Procedure to determine the current status of the modem
- */
- modem_query: procedure
-
- teststr = arg(1)
- connectstr = 'CONNECT'
- busystr = 'BUSY'
- nocarrierstr = 'NO CARRIER'
-
- test = pos(connectstr, teststr)
- if (test ~= 0) then return 100
-
- test = pos(busystr, teststr)
- if (test ~= 0) then return 0
-
- test = pos(nocarrierstr, teststr)
- if (test ~= 0) then return 0
-
- return 200
-
-
- /*
- * Subroutine to wait until a string is received from the serial port.
- */
- wait_str:
-
- teststr = arg(1)
- check = 0
- count = 0
- do until ((check ~= 0) | (count > 5))
- status = SerQuery(serhandle)
- parse upper var status valid bytes_read status_bits .
- rcvdstr = SerRead(serhandle, junk, bytes_read)
- check = pos(teststr,rcvdstr)
- test = delay(50)
- count = count + 1
- end
- if (count > 5) then return 0
- return 1
-
- /*
- * Ctrl-C signal handling routine.
- */
- break_c:
- say 'Cleaning up...'
- if (serhandle ~= 0) then
- check = SerClose(serhandle)
-
- if (buffer ~= 0) then
- check = freemem(buffer, 4096)
-
- address command
- 'offline' slip_device '0' /* Just in case AmiTCP doesn't get killed */
-
- address AMITCP
- 'KILL'
- check = delay(150)
- exit 20
-
-